home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 August: Tool Chest / Dev.CD Aug 98 TC.toast / Tool Chest / Testing & Debugging / Mac OS Development Toolkit / Automation Essentials 2.3.0 / Host Automation Folder / LaunchQuit Engine / LQCustom.lib < prev   
Encoding:
Text File  |  1998-03-19  |  6.6 KB  |  217 lines  |  [TEXT/MPS ]

  1. #########################################################################
  2. #########################################################################
  3. ##                     Copyright © Apple Computer, Inc. 1993-1997
  4. ##                                All rights reserved
  5. #########################################################################
  6. #########################################################################
  7. #    
  8. #    Library:        LQCustom.lib
  9. #    
  10. #    Version:        2.1.4
  11. #    Description:
  12. #        A library to introduce custom activities in between launch and quit.
  13. #    Contains:
  14. #        LQCustomTask()
  15. #        unexpected_window()
  16. #    
  17. #    History:
  18. #        Date:        By:        Changes:
  19. #        08/09/93    SBR        Created
  20. #        08/05/95    SBR        Added Apple Copyright header for Radar 1273925  
  21. #        09/27/96    BRL        Added SPEC Exception handling
  22. #        01/21/97    SBR        Deleted older exception code and comments.
  23. #    
  24. #########################################################################
  25. #########################################################################
  26. Libraries
  27.     "Additions.lib", 
  28.     "Clouseau.lib", 
  29.     "LaunchQuits.lib", 
  30.     "Report.lib", 
  31.     "VUAid.lib", 
  32.     "ExceptionHandling.lib",
  33.     "AutoDialogAIQ New";
  34.  
  35. #########################################################################
  36. #    task    LQCustomTask()
  37. #∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞
  38. #    Description:    The LaunchQuit engine calls this task after completing the launch,
  39. #                    before beginning the quit. This task can call other tasks, but it must
  40. #                    leave the application in the same state as when it was called, so 
  41. #                    the quit will still work.
  42. #    Parameters:        none -- to make it easy on the engine
  43. #    Returns:        true:    everything worked
  44. #                    false:    something did not work
  45. #    Examples:        see checkLaunchQuit() in LaunchQuits.lib
  46. #    Assumptions:    None
  47. #∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞
  48. #    History:
  49. #        08/09/93    SBR        Created
  50. #        03/22/94    SBR        Now returns true or false.
  51. #        09/27/96    BRL        Added SPEC Exception handling
  52. #########################################################################
  53. task LQCustomTask()
  54. begin
  55.     ### Collect all menuItems that end in '…' or '...'
  56.     
  57.     DialogMenuItemList := _Collect([menuItem t:/≈.../ e:true ]) + _Collect([menuItem t:/≈…/ e:true ]);
  58.  
  59.     println "        Collected all menu items ending in '...' and '…'";
  60.  
  61.     topWindow := _Match([window o:1], true);
  62.  
  63.     for each dialogMenuItem in DialogMenuItemList
  64.     begin
  65.         println;
  66.         theContainer := dialogMenuItem.m;
  67.         if descType(theContainer) = 'menuItem'
  68.         begin
  69.             try
  70.                 match [menuItem t:theContainer.t o:theContainer.o m:[menu t:?mT o:?mO]]!;
  71.             catch theError
  72.                 exceptionDispatcher(theError,,{"LQCustomTask()", {[menuItem t:theContainer.t o:theContainer.o m:[menu t:?mT o:?mO]]}});
  73.  
  74.             _Select([menuItem t:dialogMenuItem.t m:[menuItem t:theContainer.t o:theContainer.o m:[menu t:mT o:mO]]], true);
  75.  
  76.             println "        selected ", [menuItem t:dialogMenuItem.t m:
  77.                         [menuItem t:theContainer.t o:theContainer.o m:[menu t:mT o:mO]]]!;
  78.         end;
  79.         else
  80.         begin
  81.             _Select(dialogMenuItem);
  82.             println "        selected ", dialogMenuItem;
  83.         end;
  84.         
  85.         wait(2);
  86.         unexpected_window('window', {topWindow});
  87.     end;
  88.     
  89.     AutoDialog();
  90.     return true;
  91. end;
  92.  
  93.  
  94. ############################################################################
  95. #
  96. #
  97. #∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞
  98. #    History:
  99. #        ??/??/??    ???        Created
  100. #        09/27/96    BRL        Added SPEC Exception handling
  101. #########################################################################
  102. task unexpected_window(expectedItem := "", expectedDesc := {[]})
  103. begin
  104.     try
  105.         match[target t:?tName];
  106.     catch theError
  107.         ExceptionDispatcher(theError,,{"Match 1 in unexpected_window", {expectedItem, expectedDesc}});
  108.  
  109.     if expectedItem = "window"        #the current window may be the expected!
  110.     begin
  111.         if _Match(expectedDesc[1], true)
  112.             return false;
  113.     end;
  114.  
  115.     try
  116.         topWind := match[window o:1 t:?windTitle s:?windStyle k:?kList r:?windRect];
  117.     catch theError
  118.         ExceptionDispatcher(theError,,{"Match 2 in unexpected_window", {expectedItem, expectedDesc}});
  119.  
  120.     if not topWind        #no dialog
  121.         return false;
  122.  
  123.     (*Collect the staticText items*)
  124.     staticList := kList;
  125.     for i := card staticList to 1 step -1 begin
  126.         if (descType(staticList[i]) <> 'staticText')
  127.             staticList := remove(i, staticList);
  128.     end;
  129.     if card staticList = 1 temp := "only staticText string is: " + staticList[1].t;
  130.     else if card staticList = 0 temp := "no staticText strings present";
  131.     else temp := "multiple staticText strings, one is: " + staticList[1].t;
  132.     
  133.     println("        {windStyle} window titled '{windTitle}'; {temp}");
  134.  
  135.     (*Try the escape key*)
  136.     type_keys({escapeKey});
  137.     println("        pressed the escape key");
  138.     if await_absence(topWind,2,,,6)
  139.         return true;
  140.  
  141.     (*Try the Cancel button*)
  142.     cancelButton := _Match([button t:'Cancel' w:1], true);    ## exact match
  143.  
  144.     if cancelButton
  145.     begin
  146.         _Select(cancelButton, true);    ## exact selection
  147.  
  148.         println("        selected the Cancel button");
  149.         if await_absence(topWind,2,,,6)
  150.             return true;
  151.     end;
  152.  
  153.     (*Put button titles into a list*)
  154.     buttonList := {};
  155.     for i := 1 to card kList begin
  156.         thisContentItem := kList[i];
  157.         if thisContentItem.e and (descType(thisContentItem) = 'button')
  158.             buttonList := buttonList + {thisContentItem.t};
  159.     end;
  160.  
  161.     (*If there is just one enabled button, select it*)
  162.     if (card buttonList = 1) begin
  163.         temp := buttonList[1];
  164.         if not (temp ~= /≈launch≈/) begin
  165.             
  166.             _Select([button t:temp w:1], true);    ## exact selection
  167.  
  168.             println("        unexpected_window: selected only enabled button {temp}");
  169.         end;
  170.     end;
  171.     if await_absence(topWind,2,,,6)
  172.         return true;
  173.     
  174.     (*If there are no enabled buttons, signal a warning*)
  175.     else if (card buttonList < 1) begin
  176.         CenterOfWindowClick();
  177.         println("        clicked in the center of the window");
  178.         if await_absence(topWind,2,,,6)
  179.             return true;
  180.         else begin
  181.             println("        no way out -- need human intervention");
  182.             RStatus("{tName} IS STUCK IN A DIALOG! PLEASE DISMISS IT TO CONTINUE THE SCRIPT…",1);
  183.             while not await_absence(topWind,60,,,6)
  184.                 SysBeep();
  185.             return true;
  186.         end;
  187.     end;
  188.     else for each goodTry in {'Cancel','Done','OK','No','Yes'} begin
  189.         if isMember(goodTry, buttonList) begin
  190.             
  191.             _Select([button t:goodTry w:1], true);    ## exact selection
  192.  
  193.             println("        selected button named {goodTry}");
  194.             if await_absence(topWind,2,,,6)
  195.                 return true;
  196.         end;
  197.     end;
  198.     println("        unexpected_window: {buttonList}");
  199.     for i :=  1 to card buttonList begin
  200.         if buttonList[i].t <> ''
  201.         begin        
  202.             if _MatchBoolean(buttonList[i], true)
  203.             begin
  204.                 temp := buttonList[i].t;
  205.  
  206.                 _Select([button t:temp]);
  207.                 
  208.                 if _MatchBoolean([window s:dialog o:1], true) or _MatchBoolean([window s:movablemodal o:1], true)
  209.                     unexpected_window();
  210.             end;
  211.             
  212.             if not (_MatchBoolean([window s:dialog o:1], true) or _MatchBoolean([window s:movablemodal o:1], true))
  213.                 i := card buttonList;
  214.         end;
  215.     end;
  216. end;
  217.